home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 October / CHIP Turkiye Ekim 2000.iso / prog / naps / 04 / setup.exe / Gnucleus / GnuHash.h < prev    next >
C/C++ Source or Header  |  2000-06-24  |  2KB  |  70 lines

  1. // GnuHash.h: interface for the CGnuHash class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #if !defined(AFX_GNUHASH_H__94D2867A_188C_11D4_ACF2_00A0CC533D52__INCLUDED_)
  6. #define AFX_GNUHASH_H__94D2867A_188C_11D4_ACF2_00A0CC533D52__INCLUDED_
  7.  
  8. #if _MSC_VER > 1000
  9. #pragma once
  10. #endif // _MSC_VER > 1000
  11.  
  12. // Justin Marrese, 5/25/00
  13. // A newer GnuHash based on the old hash by me and John
  14. // The old hash trashed itself when full, losing info on even 
  15. // recent connections.  This hash has two tables, and switches
  16. // between them when full, so worst case is data stays for the
  17. // lifetime of atleast one table.
  18. // Switching is triggered by having to rehash to often.  A bad 
  19. // CreateKey function could make this happen alot ... a good
  20. // random function would make the hash table very robust.
  21. // 
  22. // Sizes are still hardcoded at this time ... some ugly 
  23. // pointer-to-pointer-to-array-of-pointer-of-pointer dynamic memmory
  24. // stuff is holding me back ....
  25. //
  26. // FindValue now returns a pointer to a key_data instead of an index.
  27. // CreateKey now returns a DWORD instead of long.
  28. // Delete is depreciated ... we just wait for the table to fill and then
  29. //      destroy it all ... rehashing makes delete extremely complex.
  30.  
  31. #define HASH_SIZE    10000    // Size of each hash table
  32. #define REHASH_VALUE    13    // Offset for rehashing
  33. #define MAX_REHASH        10    // How many rehashes we try before we consider the current
  34.                             // table too full, flush the old table, and swap tables.
  35.  
  36. class CGnuSock;
  37. class CGnuControl;
  38.  
  39. struct key_data
  40. {
  41.     GUID Guid;
  42.     CGnuSock *Origin;
  43. };
  44.  
  45. class CGnuHash  
  46. {
  47. public:
  48.     CGnuHash();
  49.     CGnuHash(CGnuControl *);
  50.     virtual ~CGnuHash();
  51.  
  52.     void Insert(GUID *, CGnuSock *);
  53.     key_data * FindValue(GUID *);
  54.  
  55. private:
  56.     bool CheckEmpty(int which);
  57.     void ClearTable(int which);
  58.     DWORD CreateKey(GUID *);
  59.     bool CompareGuid(GUID *, GUID *);
  60.     
  61.     key_data *Table[2][HASH_SIZE];
  62.     int Current, Old;
  63.     int HashEntries;
  64.     CGnuControl *GnuComm;
  65. };
  66.  
  67.  
  68.  
  69. #endif // !defined(AFX_GNUHASH_H__94D2867A_188C_11D4_ACF2_00A0CC533D52__INCLUDED_)
  70.